package com.huawei;

import com.taint.agent.FlowTaintAgent;
import com.taint.callgraph.TraceItem;
import com.taint.logger.TraceEndpoint;
import com.taint.sourcesink.MethodHook;

import java.io.IOException;
import java.util.Arrays;
import java.util.Set;


public class stack {



        public static void main(String[] args) {

            TraceItem traceItem=new TraceItem("ccc","zzz","zzzz");
            traceItem.setStacktrace("zzzz");
            System.out.println(TraceEndpoint.SOURCEENTRY.name().contains("ENTRY"));
            System.out.println(TraceEndpoint.SOURCEENTRY.name().contains("ENTRYX"));
            Arrays.asList();
            first(isEmpty("name"));
           Set<MethodHook> map= FlowTaintAgent.getMethodSinkHookMap().get("com.huawei.stack");

            //java.lang.UNIXProcess unixProcess=
           //System.out.println(new Throwable().getStackTrace());
            //printStackTrace();
        }

    private static String isEmpty(String name) {
            return name;
    }

    public static void printStackTrace(){
            Set<Thread> threads=Thread.getAllStackTraces().keySet();

            for(Thread thread:threads){

                System.out.println("Thread Name: "+thread.getName());
                System.out.println("Thread State: "+thread.getState());
                StackTraceElement[] stackTraceElements=thread.getStackTrace();
                System.out.println(Arrays.toString(stackTraceElements).replace(",","\n"));
            }

        }

        public static void first(String name){
            second();
        }

        public static void second(){
            third();
            four("name");
        }

        private static void third(){
           // Thread.currentThread().dumpStack();

            StackTraceElement[] stackTraceElements=Thread.currentThread().getStackTrace();

            //System.out.println(Arrays.toString(stackTraceElements).replace(",","\n"));
        }


    public static void four(String name){
            System.out.println(name);

            five(name);


    }

    public static void five(String name){
        //TaintLogger.info("sink enter",String.format("%s","test"));

        six("xxx");
        try {
            Range.Test();
        } catch (IOException e) {
            e.printStackTrace();
        }
       /*
        FileWatcher watcher = new FileWatcher(new String[]{"/tmp/agent/yaml"});
        try {
            watcher.start(
                    path -> {
                        String fileName=path.getFileName().toString();
                        if(fileName.equals("methods.yaml"))
                        { System.out.println("test");
                        Configuration.LoadYaml("/tmp/agent/yaml"+ File.separator+fileName);}
                    });    //参数为需要监控的目录
        } catch (IOException e) {
            e.printStackTrace();
        }
        //watcher.start();
        System.out.println(name);
        try {
            Runtime.getRuntime().exec("pwd");
        } catch (IOException e) {
            e.printStackTrace();
        }


 */
    }

    public static void six(String name){
        System.out.println(name);

        Range range=new Range();
        try {
            range.exec();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //StackTraceElement[] stackTraceElements=filter(new Throwable().getStackTrace());
        //去掉包含rasp的堆栈
       // System.out.println(Arrays.toString(stackTraceElements).replace(",","\n"));
        seven(name);
    }

    public static String seven(String name){
        System.out.println(name);

        Range range=new Range();
        try {
            range.exec();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "xxxx";

        //StackTraceElement[] stackTraceElements=filter(new Throwable().getStackTrace());
        //去掉包含rasp的堆栈
        // System.out.println(Arrays.toString(stackTraceElements).replace(",","\n"));

    }


}
